<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Register
 *
 * @author PONGPON
 */
include_once 'Classes/DBConnection.class.php';

class Register extends DBConnection {

    public function regis($username, $password) {
        $query_RecUsers = "SELECT * FROM users where 
                           username = '" . $username . "' AND password = '" . $password . "'
                            ";
        $RecUsers = mysql_query($query_RecUsers, $this->connectDatabase()) or die(mysql_error());
        $row_RecUsers = mysql_fetch_assoc($RecUsers);
        $totalRows_RecUsers = mysql_num_rows($RecUsers);
        if ($totalRows_RecUsers > 0) {
            $_SESSION['username'] = $row_RecUsers['username'];

            mysql_free_result($RecUsers);
            header("Location: ?page=home");
            return TRUE;
        } else {
            mysql_free_result($RecUsers);
            return FALSE;
        }
    }

    static public function isRegis() {
        if ($_SESSION['username'] == "" || $_SESSION['username'] == NULL || !isset($_SESSION['username'])) {
            return FALSE;
        } else {
            return TRUE;
        }
    }

    static public function checkToLoginPage() {
        if (!Register::isRegis()) {
            header("Location: ?page=login");
        } else {
            return TRUE;
        }
    }

}

?>
